package com.example.service.impl;

import com.example.dao.DietRecordDao;
import com.example.entity.DietRecord;
import com.example.service.DietRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DietRecordServiceImpl implements DietRecordService {
    @Autowired
    private DietRecordDao dietRecordDao;

    @Override
    public List<DietRecord> getAllDietRecord() {
        return dietRecordDao.findAll();
    }

    @Override
    public boolean addDietRecord(DietRecord dietRecord) {
        return dietRecordDao.insert(dietRecord) > 0;
    }

    @Override
    public boolean deleteDietRecord(Integer id) {
        return dietRecordDao.delete(id) > 0;
    }

    @Override
    public boolean updateDietRecord(DietRecord dietRecord) {
        return dietRecordDao.update(dietRecord) > 0;
    }

    @Override
    public DietRecord getDietRecordById(Integer id) {
        return dietRecordDao.findDietRecordById(id);
    }
}
